#pragma once

#include <iostream>
#include <string>

#include "FreeType.h"
#include "Character.h"

using namespace std;

class BaseQuest{
public:
	enum QUESTSTATUS { COMPLETE, FAIL, INCOMPLETE, ONGOING };
	enum DIFFICULTY { EASY, NORMAL, HARD };
private:
	string description;

	bool gameOver, rewardGiven;

	CCountdownTimer textTimer;
public:
	int difficulty;

	QUESTSTATUS questStatus;
	Character *playerInfo;

	freetype::font_data fontStyle;

	CCountdownTimer questTimer;

	BaseQuest(void) : playerInfo(NULL){
		fontStyle.init("Mission.ttf", 60);

		difficulty = 0;

		questStatus = INCOMPLETE;
		description = "Empty";

		gameOver = false;
		rewardGiven = false;
	};

	~BaseQuest(void){
	};
	
	QUESTSTATUS GetQuestStatus(void) { return questStatus; };

	virtual void InitQuest(Character *playerInfo, string description, int questTimeSeconds) {
		this->playerInfo = playerInfo;
		this->description = description;

		textTimer.StartTimer(0, 0, 5, 0);
		questTimer.StartTimer(0, 0, questTimeSeconds, 0);
	};

	virtual void RenderQuest(void) {
		glPushMatrix();
			glScalef(0.5f, 0.5f, 1.0f);
			freetype::print(fontStyle, 300, 560, "Time : %d", questTimer.GetTimeLeft() / 1000);
		glPopMatrix();

		if(questStatus == COMPLETE && textTimer.CheckIfTimerRunning()){
			freetype::print(fontStyle, 190, 250, "Mission Success");
		}else if(questStatus == FAIL && textTimer.CheckIfTimerRunning()){
			freetype::print(fontStyle, 190, 250, "Mission Fail");
		}else if(questStatus == ONGOING && textTimer.CheckIfTimerRunning()){
			freetype::print(fontStyle, 190, 250, "Mission Start");
		}
	};

	virtual bool UpdateQuest(Vector3D offset, float elapsed) {
		if(questStatus == COMPLETE && !rewardGiven){
			for(int i = 0; i < (this->difficulty + 1) * 2; i++){
				playerInfo->GetInventory()->AddItem(Item::no::POTIONS);
			}

			rewardGiven = true;
		}

		if(questStatus == COMPLETE || questStatus == FAIL){
			if(!textTimer.CheckIfTimerRunning() && !gameOver){
				textTimer.StartTimer(0, 0, 5, 0);
				gameOver = true;
			}
			
			if(textTimer.CheckIfTimerEnd() && gameOver)
				return true;
		}

		if(textTimer.CheckIfTimerRunning())
			 textTimer.UpdateTimer();

		if(questStatus == ONGOING){
			if(questTimer.CheckIfTimerRunning())
				questTimer.UpdateTimer();
		}
		
		return false; 
	};
};